home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / i / internet / software / dlinksr / cookie.c next >
Encoding:
C/C++ Source or Header  |  1993-04-01  |  2.1 KB  |  90 lines

  1. /********************************************************************/
  2. /*                                                                    */
  3. /*    Packet driver for D-LINK DE600 ethernet controller                */
  4. /*                                                                    */
  5. /*    Copyleft by P. Mayer, 1993 TU-Vienna IAEE                        */
  6. /*    All rights reserved                                                */
  7. /*                                                                    */
  8. /********************************************************************/
  9.  
  10. #include <stdlib.h>
  11. #include <tos.h>
  12. #include "cookie.h"
  13. #include <stdio.h>
  14.  
  15. #ifndef NULL
  16. #define NULL (void *)0L
  17. #endif
  18.  
  19. #define _cookiejar    *(long *)0x5A0L
  20.  
  21.  
  22. COOKIE *new_cookiejar(long n)
  23. {
  24.   register long superstack;
  25.   register COOKIE *jar,*newjar;
  26.   register long i,c;
  27.  
  28.   jar = get_cookiejar();
  29.   i=0;
  30.   if(jar) for(; jar[i].id != ENDCOOKIE; i++);  /* get size of old jar */
  31.   if(jar && jar[i].val > n) return(jar);  /* there isroom in jar */
  32.  
  33.   newjar = (COOKIE *)malloc(n*sizeof(COOKIE));/* alloc new jar */
  34.   if(jar && newjar) for(c=0; c<i; c++)
  35.   {  /* copy old jar */
  36.     newjar[c].id = jar[c].id;
  37.     newjar[c].val = jar[c].val;
  38.   }
  39.   newjar[i].id = ENDCOOKIE;  /* terminate new jar */
  40.   newjar[i].val = n;
  41.   superstack = Super((void *)0);
  42.   _cookiejar = (long)newjar;  /* install new jar */
  43.   Super((void*)superstack);
  44.   return(newjar);
  45. }
  46.  
  47. COOKIE *get_cookiejar(void)
  48. {
  49.   register long superstack;
  50.   register long cookieaddress;
  51.   
  52.   if(Super((void*)1L))
  53.   {
  54.     cookieaddress = _cookiejar;  /* return address of cookiejar */
  55.   }
  56.   else
  57.   {
  58.     superstack = Super(0L);
  59.     cookieaddress = _cookiejar;  /* return address of cookiejar */
  60.     Super((void*)superstack);
  61.   }
  62.     return (COOKIE *)cookieaddress;
  63. }
  64.  
  65. COOKIE *add_cookie(long id,long val)
  66. {
  67.   register COOKIE *jar;
  68.   if((jar = new_cookiejar(8L))==NULL) return(NULL);
  69.   while(jar->id != ENDCOOKIE) jar++;  /* search end of cookiejar */
  70.   jar->id = id;
  71.   (jar+1)->val = jar->val;  /* keep size of jar */
  72.   jar->val = val;
  73.   (jar+1)->id = ENDCOOKIE;
  74.   return(jar);
  75. }
  76.  
  77.  
  78. COOKIE *get_cookie(long id)
  79. {
  80.   register COOKIE *jar;
  81.   if((jar = get_cookiejar()) == NULL) return(NULL);
  82.   while(jar->id)
  83.   {
  84.     if(jar->id == id) return(jar);  /* find cookie */
  85.     jar++;
  86.   }
  87.   return(NULL);
  88. }
  89.  
  90.